package ua.com.infopulse.believeornevers.activities;

import ua.at.tsvetkov.util.Log;
import ua.com.infopulse.believeornevers.R;
import ua.com.infopulse.believeornevers.data.Question;
import ua.com.infopulse.believeornevers.data.RandomData;
import android.R.bool;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;

public class AcGameFlow extends Activity {
	TextView txtvQuestionField;
	Button btnTrue;
	Button btnFalse;
	RandomData randomStatements;
	boolean questionStatement;
	int rightAnswers = 0;
	int wrongAnswers = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_game_flow);
		findElements();
		randomStatements = new RandomData(this, R.array.questions);
		showNextQuestion();
		btnTrue.setOnClickListener(getTrueListener());
		btnFalse.setOnClickListener(getFalseListener());

	}

	private void findElements() {
		txtvQuestionField = (TextView) findViewById(R.id.txtvAcGameFlow);
		btnTrue = (Button) findViewById(R.id.btGameFlowTrue);
		btnFalse = (Button) findViewById(R.id.btGameFlowFalse);
	}

	private OnClickListener getFalseListener() {
		return new OnClickListener() {
			@Override
			public void onClick(View v) {
				AcGameFlow.this.onUserChoose(false);
			}
		};
	}

	private OnClickListener getTrueListener() {
		return new OnClickListener() {
			@Override
			public void onClick(View v) {
				AcGameFlow.this.onUserChoose(true);
			}
		};
	}

	private void onUserChoose(boolean decision) {
		if (decision == questionStatement) {
			rightAnswers++;
			Log.d("Answer correct!");
		} else {
			wrongAnswers++;
			Log.d("Answer wrong!");
		}
		showNextQuestion();
	}

	private void showNextQuestion() {
		Question question = randomStatements.getNext();
		Log.d("->>>>"+question==null?"null message":"all is ok");
		txtvQuestionField.setText(question.question);
		questionStatement = question.state;
	}
}
